package Game;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JTextPane;

@SuppressWarnings("serial")
public class UIGame extends JFrame {
	private int widthWindow = 800;
	private int heightWindow = 600;
	private int widthScreen;
	private int heightScreen;
	private static JLabel labelMenu;
	private ImageIcon Intro;
	private Icon icono;
	private FirstLevel lvl = new FirstLevel();
	

	private void Window() {
		widthScreen = Toolkit.getDefaultToolkit().getScreenSize().width;
		heightScreen = Toolkit.getDefaultToolkit().getScreenSize().height;
		setSize(widthWindow, heightWindow);
		setLocation(widthScreen / 2 - widthWindow / 2, heightScreen / 2
				- heightWindow / 2);
		setTitle("Project");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		mainMenu();
	}

	private void mainMenu() {
		//Background of the main menu
		Intro = new ImageIcon("Resources/Menu/MainMenu.gif");
		icono = new ImageIcon(Intro.getImage().getScaledInstance(
		getWidth(), getHeight(), Image.SCALE_DEFAULT));
		labelMenu = new JLabel();
		labelMenu.setIcon(icono);
		JTextPane jtextStart = new JTextPane();
		jtextStart.setBounds(widthScreen / 2 - widthWindow / 2, heightScreen
				/ 2 - heightWindow / 2, 80, 50);
		Font font = new Font("TimesRoman", Font.BOLD, 30);
		String[] list = { "Start", "Exit", "About Project" };
		final JList textMenu = new JList(list);

		textMenu.setSelectionBackground(new Color(0, 0, 0, 0));
		textMenu.setForeground(Color.WHITE);
		textMenu.setSelectionForeground(Color.YELLOW);
		textMenu.setOpaque(false);
		textMenu.setFont(font);
		textMenu.setBackground(new Color(0, 0, 0, 0));
		textMenu.setBounds(widthScreen / 2 - widthWindow / 2, heightScreen / 2
				- heightWindow / 2, 220, 150);
		labelMenu.add(textMenu);
		this.add(labelMenu);

		textMenu.addKeyListener((new KeyListener() {

			@Override
			public void keyTyped(KeyEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void keyReleased(KeyEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void keyPressed(KeyEvent e) {
				if ((e.getKeyCode()) == 10) {
					if ((textMenu.getSelectedIndex()) == 0) {
						lvl.StartGame();
						setVisible(false);
					} else if ((e.getKeyCode()) == 10) {
						if ((textMenu.getSelectedIndex()) == 1) {
							int confirm = JOptionPane.showConfirmDialog(null,
									"Exit?");
							if (confirm == 0) {
								System.exit(0);
							}
						}

					}
				}
			}
		}));
	}

	public UIGame() {
		Start();
	}

	private void Start() {
		Window();
		setVisible(true);

	}

	public static void main(String[] args) {
		new UIGame();

	}

	public void paint(Graphics g) {
		resizeJlabel();
	}

	private void resizeJlabel() {
		Intro = new ImageIcon("Resources/Menu/MainMenu.gif");
		icono = new ImageIcon(Intro.getImage().getScaledInstance(getWidth(),
				getHeight(), Image.SCALE_DEFAULT));
		labelMenu.setIcon(icono);
	}
}